﻿using System;
using System.Collections.Generic;
using Ue.Infrastructure.DomainBase;
using Ue.Infrastructure.RepositoryFramework;
using Ue.Qcdz.Domain.Membership;
using Ue.Qcdz.Domain.SaleCategorys;
using Ue.Qcdz.Domain.ShopArticle;
using Ue.Qcdz.Domain.ShopSinglePages;
using Ue.Qcdz.Domain.SaleInfos;
namespace Ue.Qcdz.Domain.Shops
{
    public class ShopService
    {
        private static IShopRepository repository;

        static ShopService()
        {
            ShopService.repository = RepositoryFactory.GetRepository<IShopRepository, Shop>();
        }
        public static Shop GetShop(object shopKey)
        {
            return ShopService.repository.FindBy(shopKey);
        }
        public static Shop GetShop(User user)
        {
            return ShopService.repository.GetShop(user);
        }

        public static IList<Shop> GetShop()
        {
            return ShopService.repository.FindAll();
        }
        public static IDataResult<Shop> GetShop(IShopDataQuery dataQuery)
        {
            return ShopService.repository.FindBy(dataQuery);
        }

        public static void AddShop(Shop shop)
        {
            ShopService.repository.Add(shop);
        }

        public static void RemoveShop(Shop shop)
        {
            ShopService.repository.Remove(shop);
        }
        public static void RemoveShop(object shopKey)
        {
            Shop shop = ShopService.repository.FindBy(shopKey);
            if (shop == null)
                throw new ArgumentOutOfRangeException("shopKey");
            //删除产品
               SaleInfoService.RemoveAll(shop);
            //删除类别
            SaleCategoryService.RemoveAll(shop);
            //删除新闻
            ShopNewsService.RemoveAll(shop);
            //删除单页
            ShopSinglePageService.RemoveAll(shop);
            //删除商铺
            ShopService.repository.Remove(shop);
        }

        public static void UpdateShop(Shop shop)
        {
            ShopService.repository[shop.Key] = shop;
        }
    }
}
